<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/23
 * Time: 14:53
 */

namespace Controller;

use Model\LoginModel;
use Shop\Controller; //引入控制器父类

//继承也会 触发自动加载
class LoginController extends Controller{
    //显示验证码方法
    public function idenYzm(){
        $this->yzm();
    }
    public function login(){
        //显示页面
        if($_POST['submit']){
            //提交
            $yzm=$_POST['yzm'];
            $user=$_POST['user'];
            $pass=$_POST['pass'];

//            判断验证码
            if($yzm!=$_SESSION[SHOP]['yzm']){
               $this->success('验证码错误');
            }
            //操作数据库查看用户名和密码
            $model=new LoginModel();
            $arr=$model->getAdmin(); //得到管理员数据
            if($arr['user']!=$user){
                $this->success('用户名不存在');
            }
            if($arr['pass']!=$pass){
                $this->success('密码错误');
            }
            //保存信息的session
            $_SESSION[SHOP]['admin']=$arr;

            //修改信息
            if($_POST['online']){
                $stat=$_POST['online'];
                $model->pdo_upd("sh_admin",array('ip'=>$_SERVER['REMOTE_ADDR'],'time'=>date('Y-m-d H:i:s',time()),'stat'=>"$stat"),'');
                setcookie('user',"$pass",time()+7200,'/');
            }else{
                $model->pdo_upd("sh_admin",array('ip'=>$_SERVER['REMOTE_ADDR'],'time'=>date('Y-m-d H:i:s',time()),'stat'=>"0"),'');
            }

            $this->success('登录成功',"Index",'index');
        }else{
            $this->view->display();
        }


    }
}